home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 October / EnigmA AMIGA RUN 01 (1995)(G.R. Edizioni)(IT)[!][issue 1995-10][Aminet 7].iso / Aminet / util / cli / CD32goodies.lha / cd32ctrl.c < prev    next >
C/C++ Source or Header  |  1995-04-22  |  3KB  |  116 lines

  1. /*
  2.     CD³²Ctrl - controlls several features of your CD³² games console
  3.  
  4.     this is just an AmigaDOS frontend for the lowlevel.library function
  5.     SystemControl(). written by Daniel Balster
  6.  
  7.     example usage:
  8.     
  9.     CD32CTRL NOREQ NOCDREBOOT ; no more requesters & cdeject-resets
  10.     CD32CTRL REQ CDREBOOT     ; the opposite...
  11.  
  12.     do not offer both (i.e. REQ NOREQ) i won't check that.
  13.  
  14.     (not much comments in it - forgive me)
  15. */
  16.  
  17. #include <exec/exec.h>
  18. #include <dos/dos.h>
  19. #include <libraries/lowlevel.h>
  20. #include <devices/cd.h>
  21. #include <proto/exec.h>
  22. #include <proto/dos.h>
  23. #include <proto/lowlevel.h>
  24.  
  25. #define TEMPLATE "REQ/S,NOREQ/S,CDREBOOT/S,NOCDREBOOT/S,EJECTRESET/S,NOEJECTRESET/S,SPEED/K,QUIET/S"
  26.  
  27. struct abc {
  28.     ULONG    req,noreq,res,nores,eject,noeject,speed;
  29.     ULONG    quiet;
  30.     ULONG    pads[8]; /* someone said RDArgs must be sized to a 16-longs boundary ??? */
  31. };
  32.  
  33. struct TagItem CfgSpeed[] =
  34. {
  35.     { TAGCD_READSPEED, 150 },
  36.     { TAG_END, 0 }
  37. };
  38.  
  39. struct TagItem CfgEject[] =
  40. {
  41.     { TAGCD_EJECTRESET, FALSE },
  42.     { TAG_END, 0 }
  43. };
  44.  
  45. int main (void)
  46. {
  47.     struct RDArgs *rdargs;
  48.     struct abc args = {0};
  49.     struct MsgPort *mp;
  50.     struct IOStdReq *ior;
  51.     
  52.     if (rdargs=ReadArgs(TEMPLATE,(LONG*)&(args),NULL))
  53.     {
  54.         if(!args.quiet)
  55.             PutStr("*** CD³²Ctrl Version 1.0.0 *** by Daniel Balster\n");
  56.  
  57.         if(mp=CreateMsgPort())
  58.         {
  59.             if(ior=(struct IOStdReq*)CreateIORequest(mp,sizeof(struct IOStdReq)))
  60.             {
  61.                 if(!OpenDevice("cd.device",0,ior,0))
  62.                 {
  63.                     /* ok, the following is somehow ugly - but who carez */
  64.                 
  65.                     if (args.eject)
  66.                     {
  67.                         CfgEject[0].ti_Data = TRUE;
  68.                         ior->io_Command    = CD_CONFIG;
  69.                         ior->io_Data    = (APTR) &CfgEject;
  70.                         ior->io_Length    = 0;
  71.                         DoIO(ior);
  72.                     }
  73.  
  74.                     if (args.noeject)
  75.                     {
  76.                         CfgEject[0].ti_Data = FALSE;
  77.                         ior->io_Command    = CD_CONFIG;
  78.                         ior->io_Data    = (APTR) &CfgEject;
  79.                         ior->io_Length    = 0;
  80.                         DoIO(ior);
  81.                     }
  82.  
  83.                     if (args.speed)
  84.                     {
  85.                         CfgSpeed[0].ti_Data = *(ULONG*)args.speed;
  86.                         ior->io_Command    = CD_CONFIG;
  87.                         ior->io_Data    = (APTR) &CfgSpeed;
  88.                         ior->io_Length    = 0;
  89.                         DoIO(ior);
  90.                     }
  91.                 
  92.                     CloseDevice((struct IORequest*)ior);
  93.                 }
  94.                 else PutStr("cannot access cd.device?\n");
  95.                 
  96.                 DeleteIORequest((struct IORequest*)ior);
  97.             }
  98.             else PutStr("cannot create ioreq?\n");
  99.  
  100.             DeleteMsgPort(mp);
  101.         }
  102.         else PutStr("cannot create msgport?\n");
  103.  
  104.  
  105.         if (args.req) SystemControl(SCON_KillReq,FALSE,TAG_END);
  106.         if (args.noreq) SystemControl(SCON_KillReq,TRUE,TAG_END);
  107.         if (args.res) SystemControl(SCON_CDReboot,CDReboot_On,TAG_END);
  108.         if (args.nores) SystemControl(SCON_CDReboot,CDReboot_Off,TAG_END);
  109.  
  110.         FreeArgs(rdargs);
  111.     }
  112.     else PrintFault(IoErr(),0);
  113.  
  114.     return RETURN_OK;
  115. }
  116.